﻿function callMyPanel(panelName, arg) 
{ 
    if(fl.swfPanels.length > 0){ 
        for(x = 0; x < fl.swfPanels.length; x++){ 
            // look for a SWF panel of the specified name, then call the specified AS3 function 
            // in this example, the panel is named "test" and the AS3 callback is "callMySWF" 
            if(fl.swfPanels[x].name == panelName) // name busted? 
            { 
                fl.swfPanels[x].call("callLibraryItemInspectorSWF",arg); 
                break; 
            } 
        } 
    }else {
        fl.trace("no panels"); 
	}
}

var item;
if(fl.getDocumentDOM().selection.length>0){
	var ele = fl.getDocumentDOM().selection[0];
	if(ele.libraryItem){
		inspectSelection(ele.libraryItem);
	}
}

function inspectSelection(libraryItem){
	item = libraryItem;
	var name = item.name.substring(item.name.lastIndexOf('/') + 1, item.name.length);
	var arg = '';
	for(var prop in item){
		arg += prop + ':' + item[prop] + '|';
	}
	callMyPanel('LibraryItemInspector', arg);
}

fl.addEventListener("mouseMove", onMouseMove);

function onMouseMove(){
	var ele = fl.getDocumentDOM().selection[0];
	if(ele.libraryItem){
		if(ele.libraryItem.name != item.name)inspectSelection(ele.libraryItem);
	}
}

//定位元素库元件在库中的位置.
function findIt(){
	var lbItem = item;
	
	if(lbItem){
		if(lbItem.name.lastIndexOf('/')>0){
			var pathNames = lbItem.name.split('/');
			var path = '';
			for(var j=0; j<pathNames.length; j++){
				path += (j==0?'':'/') + pathNames[j];
				fl.getDocumentDOM().library.expandFolder(true, false, path);
			}
			
		}
		fl.getDocumentDOM().library.selectItem(lbItem.name);
	}
}